﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using XZTZ.UMP.Public.Models.Flow;
using XZTZ.UMP.WEB.Data;

namespace XZTZ.UMP.WEB.Pages.Flow.FlowTemplate
{
    public class IndexModel : PageModel
    {
        private readonly XZTZ.UMP.WEB.Data.ApplicationDbContext _context;

        public IndexModel(XZTZ.UMP.WEB.Data.ApplicationDbContext context)
        {
            _context = context;
        }

        public Guid visionId { get; set; }
        public string busid { get; set; }
        public IList<Flow_Template> Flow_Template { get; set; }
        public async Task OnGetAsync()
        {
            if (HttpContext.Session.GetString("visionId") != null && HttpContext.Session.GetString("bussid") != null)
            {
                visionId = new Guid(HttpContext.Session.GetString("visionId"));
                busid = HttpContext.Session.GetString("bussid");
            }
            else
            {
                visionId = new Guid(Request.Query["visionId"].ToString());
                busid = Request.Query["bussId"].ToString();
                if (Request.Query["visionId"].ToString() != null && Request.Query["visionId"].ToString() != "" && Request.Query["bussId"].ToString() != null && Request.Query["bussId"].ToString() != "")
                {
                    HttpContext.Session.SetString("visionId", Request.Query["visionId"].ToString());
                    HttpContext.Session.SetString("bussid", busid);
                }
            }

            Flow_Template = await _context.Flow_Template.Where(m => m.guiVisonID == visionId && m.strBusinessTypeID == busid).ToListAsync();
            // Flow_Templ= await _context.Flow_Template.ToListAsync();

        }
    }
}
